package com.qf.air.controller;

import com.qf.air.entity.Air;
import com.qf.air.service.AirService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.xml.crypto.Data;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @Author: llf
 * @Date: 2021/3/24 14:43
 */
@RestController
@RequestMapping(value = "/air")
@CrossOrigin(allowCredentials = "true")
public class AirController {

    @Autowired
    private AirService airService;

    /**
     查询空气质量信息
     #请求路径和请求方式
     GET		http://localhost:8080/air/list
     # 请求参数
     page = 当前页(int)
     rows = 每页显示条数(int)
     districtId = 区域的标识(int)
     */
    @RequestMapping(value = "/list",method = RequestMethod.POST)
    public Object[] list(@RequestBody Map map) throws ParseException {
        Integer page = (Integer) map.get("page");
        Integer rows = (Integer) map.get("rows");
        Integer districtId = (Integer) map.get("districtId");
        String monitoringStation = (String) map.get("monitoringStation");
        Object longStart = map.get("startTime");
        Object longEnd = map.get("endTime");
        return airService.findByPageAndDistrictId(page,rows,districtId,monitoringStation,longStart,longEnd);
    }

    /**
     * 添加空气质量信息
     * @param air
     */
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public void add(@RequestBody Air air){
        airService.save(air);
    }

    /**
     * 删除空气质量信息
     * @param id
     */
    @DeleteMapping ("/delete/{id}")
    public void delete(@PathVariable Integer id){
        airService.deleteById(id);
    }

    /**
     * 修改空气质量信息
     * @param air
     */
    @PostMapping("/update")
    public void update(@RequestBody Air air){
        airService.updateById(air);
    }
}
